﻿using NuGet.Protocol;
using NuGet.Protocol.Core.Types;
using System.Net;

namespace DllDependenciesAnalysis
{
    public class NugetRuntime
    {
        public SourceCacheContext Cache { get; }
        public SourceRepository SourceRepository { get; }
        public FindPackageByIdResource Resource { get; }
        public string NugetUrl { get; }

        public NugetRuntime(string url)
        {
            NugetUrl = url;

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
                                       | SecurityProtocolType.Tls
                                       | SecurityProtocolType.Tls11
                                       | SecurityProtocolType.Tls12;

            Cache = new SourceCacheContext();
            SourceRepository = Repository.Factory.GetCoreV3(url);
            Resource = SourceRepository.GetResourceAsync<FindPackageByIdResource>().Result;
        }
    }
}
